import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    state.routes = [
      // 合并原有的静态路由
      ...constantRoutes,
      ...data
    ]
  }
}
const actions = {
  filterRoutes(store, menus) {
    const newAsyncRoutes = asyncRoutes.filter(item => menus.includes(item.name))
    console.log(menus)
    console.log('筛选的路由', newAsyncRoutes)
    // 利用mutations共享数据进行routes的传递
    // 这里是筛选出可访问的动态路由
    store.commit('setRoutes', newAsyncRoutes)
    // 返回供 addRoutes 使用
    return newAsyncRoutes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
